﻿using Csla;
using Csla.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BO
{
    public class ListFactory<T> where T:IBusinessList,new()
    {
        internal static T GetList(SafeDataReader dr)
        {
            return GetList(null, dr, true);
        }

        internal static T GetList(BusinessBaseEx pHeader, SafeDataReader dr)
        {
            return GetList(pHeader, dr, true);
        }

        internal static T GetList(SafeDataReader dr, bool IsCheckDuplicate)
        {
            return GetList(null, dr, IsCheckDuplicate);
        }

        internal static T GetList(BusinessBaseEx pHeader, SafeDataReader dr, bool IsCheckDuplicate)
        {
            T list = new T();
            list.SetHeader(pHeader);
            list.Fetch(dr, IsCheckDuplicate);
            return list;
        }


        public static T GetList(string pFilter)
        {
            return GetList("", pFilter, "", 0, false);
        }

        public static T GetList(string pFilter, string pSortString)
        {
            return GetList("", pFilter, pSortString, 0, false);
        }
        public static T GetList(string pFilter, string pSortString, int topN)
        {
            return GetList("", pFilter, pSortString, topN, false);
        }
        public static T GetList(string pCustomJoin, string pFilter, string pSortString)
        {
            return GetList(pCustomJoin, pFilter, pSortString, 0, false);
        }
        public static T GetList(string pCustomJoin, string pFilter, string pSortString, int topN)
        {
            return GetList(pCustomJoin, pFilter, pSortString, topN, false);
        }
        public static T GetList(string pCustomJoin, string pFilter, string pSortString, bool pIsDistinct)
        {
            return GetList(pCustomJoin, pFilter, pSortString, 0, pIsDistinct);
        }
        public static T GetList(string pCustomJoin, string pFilter, string pSortString, int pTopInt, bool pIsDistinct, params SerSqlParameter[] parameters)
        {

            return DataPortal.Fetch<T>(new ListCriteria(pCustomJoin, pFilter, pSortString, pTopInt, pIsDistinct,parameters));
        }


    }
}
